//
//  C_SongListCollectionViewCell.m
//  音悦咖
//
//  Created by Best on 15/7/15.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "C_SongListCollectionViewCell.h"

@implementation C_SongListCollectionViewCell

- (void)dealloc
{
    [_imageView release];
    [_nameLabel release];
    [_songLabel release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self create];
    }
    return self;
}

- (void)create
{
    self.imageView = [[UIImageView alloc] init];
    [self addSubview:self.imageView];
    [_imageView release];
    
    
    self.songLabel = [[UILabel alloc] init];
    [self addSubview:self.songLabel];
    [self.songLabel setTextAlignment:(NSTextAlignmentRight)];
    //elf.songLabel.backgroundColor = RGBA(231, 231, 231, 1);
    [_songLabel release];
    
    
    self.nameLabel = [[UILabel alloc] init];
    [self addSubview:self.nameLabel];
    [self.nameLabel setTextAlignment:(NSTextAlignmentRight)];
    [self.nameLabel setFont:[UIFont systemFontOfSize:15]];
    self.nameLabel.textColor = RGBA(180, 180, 180, 0.8);
    [_nameLabel release];
 
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    
    CGFloat width = layoutAttributes.frame.size.width;
    CGFloat height = layoutAttributes.frame.size.height;
    
    self.imageView.frame = CGRectMake(10, 5, width / 3, height - 10);
    self.songLabel.frame = CGRectMake(self.imageView.frame.origin.x + self.imageView.frame.size.width, 20, width - self.imageView.frame.origin.x - self.imageView.frame.size.width - 20, 30);
    self.songLabel.textColor = WHITE;
    self.nameLabel.frame = CGRectMake(self.imageView.frame.origin.x + self.imageView.frame.size.width, height - 30, width - self.imageView.frame.origin.x - self.imageView.frame.size.width - 10, 20);
    self.nameLabel.textColor = WHITE;
    
    
}

- (void)setModel:(C_SonglistModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    [self.imageView setImageWithURL:model.pic];
    NSArray *arr = [model.title componentsSeparatedByString:@" - "];
    self.songLabel.text = arr[1];
    self.nameLabel.text = arr[0];
   
}

@end
